import { ref } from "vue";
import { URL_TOKEN_RECOMMEND } from "@/comm/api";
import { get } from "@/comm/request";

const hotToken = ref<HotToken[]>([]);
const activeAddress = ref<string[]>([]);

function getData() {
    get<SucDate>(URL_TOKEN_RECOMMEND, {}).then(res => {
        if (res.success) {
            hotToken.value = res.data.hotToken.filter(i => i.name);
            activeAddress.value = res.data.activeAddress;
            // activeAddress.value.length = 5;
            // console.log('yzt', res.data);
        }
    });
}

const onTagDown = function (item: HotToken | string) {
    if (typeof item === "string") {
        window.open("/address/" + item);
    } else {
        window.open("/token/" + item.tokenAddress);
    }
    // console.log('yzt', item);
};

export { hotToken, activeAddress, getData, onTagDown };

interface SucDate {
    success: boolean;
    data: Data;
}

interface Data {
    activeAddress: string[];
    hotToken: HotToken[];
}

interface HotToken {
    id: string;
    decimals: string;
    dex: string;
    name: string;
    symbol: string;
    tokenAddress: string;
    syncDay: number;
    syncHour?: any;
    endTime?: number;
    hourEndTime?: number;
    marketCap?: any;
    fullyDilutedMarketCap?: any;
    maxSupply?: any;
    totalSupply?: any;
}
